package com.emergency.evaluate.service.impl;

import com.emergency.common.util.CommonUtils;
import com.emergency.common.util.IdWorker;
import com.emergency.evaluate.dao.AutoscoreDao;
import com.emergency.evaluate.domain.Autoscore;
import com.emergency.evaluate.service.AutoscoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2020/3/16.
 */
@Service
public class AutoScoreServiceImpl implements AutoscoreService {

    @Autowired
    private AutoscoreDao autoscoreDao;

    @Autowired
    private IdWorker idWorker;


    //录入自动评分数据
    @Override
    public  List<Autoscore> add(List<Autoscore> autoscoreList) {
        for (Autoscore autoscore : autoscoreList) {  //肯定会录入指标ID
            if (CommonUtils.isNullOrEmpty ( autoscore.getId () )) {
                autoscore.setId ( idWorker.nextId () );
                autoscore.setCreateTime ( new Date () );
                autoscoreDao.save ( autoscore );
            }
            //从数据库里读取初始数据、结束时的数据,这里举了三个例子
            //autoscore.setDataStart (  );
            //autoscore.setDataEnd (  );
        if (!CommonUtils.isNullOrEmpty ( autoscoreDao.findAllById ( autoscore.getId () ) )){
            Autoscore autoscore1 = autoscoreDao.findAllById ( autoscore.getId () );
            if (autoscore1.getExtract ().getIndicator ().getContext ().contains (  "一回路压力" )) {

                autoscore1.setDataStart ( 18.0 );
                autoscore1.setDataEnd ( 15.6 );
                autoscore1.setDataStandard ( 15.5 );
                autoscore1.setDatamax ( 17.2 );
                autoscore1.setDatamin ( 15 );
                autoscoreDao.save ( autoscore1 );
            }
            if (autoscore1.getExtract ().getIndicator ().getContext ().contains ( "二回路蒸汽压力" )) {
                autoscore1.setDataStart ( 9 );
                autoscore1.setDataEnd ( 6 );
                autoscore1.setDataStandard ( 7 );
                autoscore1.setDatamax ( 9 );
                autoscore1.setDatamin ( 5 );
                autoscoreDao.save ( autoscore1 );
            }
            if (autoscore1.getExtract ().getIndicator ().getContext ().contains ( "压力容器温度" )) {
                autoscore1.setDataStart ( 386 );
                autoscore1.setDataEnd ( 350 );
                autoscore1.setDataStandard ( 325 );
                autoscore1.setDatamax ( 345 );
                autoscore1.setDatamin ( 300 );
                autoscoreDao.save ( autoscore1 );
            }
            }
        }
        return  autoscoreDao.findAll ();
    }

    //保存
    @Override
    public List<Autoscore> save( List<Autoscore> autoscoreList){
       autoscoreDao.saveAll ( autoscoreList );
       return autoscoreList;
    }



}
